<template>
  <el-dialog
    :show-close="showClose"
    :model-value="visible"
    :title="title"
    :width="width"
    draggable
    :top="top + 'px'"
    class="custom-dialog"
    @close="close"
  >
    <div
      class="dialog-body"
      :style="{ 'max-height': maxHeight + 'px', padding: padding + 'px' }"
    >
      <slot></slot>
    </div>

    <template #footer>
      <span class="dialog-footer">
        <slot name="footer"></slot>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
const props = defineProps({
  title: {
    type: String,
  },
  visible: {
    type: Boolean,
    default: false,
  },
  showClose: {
    type: Boolean,
    default: true,
  },
  top: {
    type: Number,
    default: 50,
  },
  width: {
    type: [String, Number],
    default: "30%",
  },
  padding: {
    type: Number,
    default: 15,
  },
});

const maxHeight = window.innerHeight - props.top - 100;

const emit = defineEmits(["close"]);
const close = () => {
  emit("close");
};
</script>

<style lang="scss" scoped>
.custom-dialog {
  margin: 30px auto 10px !important;

  :deep(.el-dialog__body) {
    padding: 0;
  }

  .dialog-body {
    border-top: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
    min-height: 80px;
    overflow: auto;
  }

  .dialog-footer {
    text-align: right;
    padding: 5px 20px;
  }
}
</style>
